from django.shortcuts import render, redirect
from django.http import HttpResponse
# Create your views here.
from django.urls import reverse

from poem.forms import PoetForm, PoemForm
from poem.models import PoetModel, PoemModel


def poet_add(request):
    if request.method == 'POST':
        form = PoetForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse("poet:all"))
    else:
        form = PoetForm()
    return render(request, 'poet/add.html',{"form":form})

def poet_all(request):

    poets = PoetModel.objects.all()
    return render(request, 'poet/all.html', {'poets':poets})

def poem_add(request):
    if request.method == 'POST':
        form = PoemForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse("poem:all"))
    else:
        form = PoemForm()
    return render(request, 'poem/add.html', {"form": form})

def poem_all(request):
    poems = PoemModel.objects.all()
    return render(request, 'poem/all.html', {'poems': poems})